package com.hmall.item.consumer;

import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
public class SpringRabbitListener {
    // 利用RabbitListener来声明要监听的队列信息
    // 将来一旦监听的队列中有了消息，就会推送给当前服务，调用当前方法，处理消息。
    // 可以看到方法体中接收的就是消息体的内容
//    @RabbitListener(queues = "simple.queue") todo 未指定交换机
    public void listenSimpleQueueMessage(String msg) throws InterruptedException {
        System.out.println("spring 消费者接收到消息：【" + msg + "】");
    }

    // 延迟队列
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = "delay.queues", durable = "true"),
            exchange = @Exchange(value = "delay.directs", delayed = "true"),
            key = "hi"
    ))
    public void listenDelayQueue(String msg) {
        System.out.println("spring 消费者接收到消息：【" + msg + "】");
    }
}